/*     */ package com.feeyin.radar.sys.service.impl;
/*     */ 
/*     */ import com.feeyin.radar.commons.DateUtils;
/*     */ import com.feeyin.radar.commons.FileUtils;
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.sys.dao.BackupDataDAO;
/*     */ import com.feeyin.radar.sys.dao.ManageSetDAO;
/*     */ import com.feeyin.radar.sys.form.BackupForm;
/*     */ import com.feeyin.radar.sys.model.BackupData;
/*     */ import com.feeyin.radar.sys.model.ManageSet;
/*     */ import com.feeyin.radar.sys.service.BackupDataService;
/*     */ import com.feeyin.radar.task.ChangeCronExpression;
/*     */ import java.io.File;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ 
/*     */ public class BackupDataServiceImpl
/*     */   implements BackupDataService
/*     */ {
/*     */   private BackupDataDAO backupDataDAO;
/*     */   private ManageSetDAO manageSetDAO;
/*     */   private ChangeCronExpression changeCronExpression;
/*     */ 
/*     */   public BackupDataDAO getBackupDataDAO()
/*     */   {
/*  33 */     return this.backupDataDAO;
/*     */   }
/*     */ 
/*     */   public void setBackupDataDAO(BackupDataDAO backupDataDAO) {
/*  37 */     this.backupDataDAO = backupDataDAO;
/*     */   }
/*     */ 
/*     */   public List getPageBackupDatas(String realPath) {
/*  41 */     List list = new ArrayList();
/*  42 */     if (StringUtils.isEmpty(realPath)) return null;
/*  43 */     String backupPath = realPath + "backup" + System.getProperty("file.separator");
/*  44 */     File file = new File(backupPath);
/*  45 */     if ((file.exists()) && (file.isDirectory())) {
/*  46 */       List backupFiles = new ArrayList();
/*  47 */       list = getBackupFiles(file, backupFiles);
/*     */     }
/*     */ 
/*  50 */     return list;
/*     */   }
/*     */ 
/*     */   public BackupData getBackupData(Integer id)
/*     */   {
/*  58 */     return this.backupDataDAO.getBackupData(id);
/*     */   }
/*     */ 
/*     */   public ManageSetDAO getManageSetDAO() {
/*  62 */     return this.manageSetDAO;
/*     */   }
/*     */ 
/*     */   public void setManageSetDAO(ManageSetDAO manageSetDAO) {
/*  66 */     this.manageSetDAO = manageSetDAO;
/*     */   }
/*     */ 
/*     */   public ChangeCronExpression getChangeCronExpression() {
/*  70 */     return this.changeCronExpression;
/*     */   }
/*     */ 
/*     */   public void setChangeCronExpression(ChangeCronExpression changeCronExpression) {
/*  74 */     this.changeCronExpression = changeCronExpression;
/*     */   }
/*     */ 
/*     */   public boolean insertBackupData(String realPath, String backupWay) {
/*  78 */     if (StringUtils.isEmpty(realPath)) return false;
/*  79 */     if (StringUtils.isEmpty(backupWay)) return false;
/*  80 */     String[] array = new String[3];
/*  81 */     boolean result = false;
/*     */     try {
/*  83 */       array = FileUtils.createExcuteBackUpBatFile(realPath, backupWay);
/*  84 */       if ((array == null) || (array.length <= 0)) return false;
/*  85 */       if ((array[0] == null) || (array[1] == null) || (array[2] == null)) return false;
/*  86 */       File file = new File(array[2] + array[1]);
/*  87 */       if ((file.exists()) && (file.isFile()))
/*     */       {
/*  89 */         BackupData backupData = new BackupData();
/*  90 */         backupData.setBackupDate(DateUtils.stringDateConvertDate(array[0], "yyyy-MM-dd HH:mm:ss"));
/*  91 */         backupData.setBackupName(array[1]);
/*  92 */         backupData.setBackupWay(backupWay);
/*  93 */         backupData.setPath(array[2]);
/*  94 */         this.backupDataDAO.insertBackupData(backupData);
/*     */ 
/*  96 */         result = true;
/*     */       }
/*     */     } catch (Exception e) {
/*  99 */       e.printStackTrace();
/*     */     }
/* 101 */     return result;
/*     */   }
/*     */ 
/*     */   public boolean restoreData(String realPath, String path) {
/* 105 */     boolean result = false;
/*     */     try {
/* 107 */       if (StringUtils.isEmpty(path)) return false;
/*     */ 
/* 112 */       result = FileUtils.createRestoreBackUpBatFile(realPath, path);
/*     */     } catch (Exception e) {
/* 114 */       e.printStackTrace();
/*     */     }
/* 116 */     return result;
/*     */   }
/*     */ 
/*     */   public BackupForm getBackupPlan()
/*     */   {
/* 156 */     List list = new ArrayList();
/* 157 */     list = this.manageSetDAO.getManageSetByType("6");
/* 158 */     if ((list == null) || (list.size() <= 0)) return null;
/*     */ 
/* 160 */     String backupCycle = "";
/* 161 */     String week = "";
/* 162 */     String hour = "";
/* 163 */     String minute = "";
/* 164 */     for (int i = 0; i < list.size(); i++) {
/* 165 */       ManageSet manageSet = new ManageSet();
/* 166 */       manageSet = (ManageSet)list.get(i);
/* 167 */       if ((StringUtils.isEmpty(manageSet.getStatus())) || 
/* 168 */         (!"1".equals(manageSet.getStatus()))) continue;
/* 169 */       if ("backupCycle".equals(manageSet.getCode()))
/* 170 */         backupCycle = manageSet.getMValue();
/* 171 */       else if ("backupWeek".equals(manageSet.getCode()))
/* 172 */         week = manageSet.getMValue();
/* 173 */       else if ("backupHour".equals(manageSet.getCode()))
/* 174 */         hour = manageSet.getMValue();
/* 175 */       else if ("backupMinute".equals(manageSet.getCode())) {
/* 176 */         minute = manageSet.getMValue();
/*     */       }
/*     */ 
/*     */     }
/*     */ 
/* 181 */     BackupForm backupForm = new BackupForm();
/* 182 */     if ((!StringUtils.isEmpty(backupCycle)) && 
/* 183 */       (!StringUtils.isEmpty(hour)) && 
/* 184 */       (!StringUtils.isEmpty(minute))) {
/* 185 */       backupForm.setBackupCycle(backupCycle);
/* 186 */       backupForm.setHour(hour);
/* 187 */       backupForm.setMinute(minute);
/* 188 */       if (!StringUtils.isEmpty(week)) {
/* 189 */         backupForm.setWeek(week);
/*     */       }
/*     */     }
/*     */ 
/* 193 */     return backupForm;
/*     */   }
/*     */ 
/*     */   public boolean insertBackupPlan(BackupForm backupForm) {
/* 197 */     if (backupForm == null) return false;
/* 198 */     if (StringUtils.isEmpty(backupForm.getBackupCycle())) return false;
/* 199 */     if (StringUtils.isEmpty(backupForm.getHour())) return false;
/* 200 */     if (StringUtils.isEmpty(backupForm.getMinute())) return false;
/*     */ 
/* 202 */     if ("2".equals(backupForm.getBackupCycle())) {
/* 203 */       if (StringUtils.isEmpty(backupForm.getWeek())) return false;
/* 204 */       updateBackupPlan("backupWeek", backupForm.getWeek(), "1");
/*     */     } else {
/* 206 */       updateBackupPlan("backupWeek", "0", "0");
/*     */     }
/* 208 */     updateBackupPlan("backupCycle", backupForm.getBackupCycle(), "1");
/* 209 */     updateBackupPlan("backupHour", backupForm.getHour(), "1");
/* 210 */     updateBackupPlan("backupMinute", backupForm.getMinute(), "1");
/*     */ 
/* 212 */     this.changeCronExpression.changeBackupCronExpression();
/* 213 */     return true;
/*     */   }
/*     */ 
/*     */   private boolean updateBackupPlan(String code, String value, String status)
/*     */   {
/* 223 */     if (StringUtils.isEmpty(code)) return false;
/* 224 */     if (StringUtils.isEmpty(value)) return false;
/* 225 */     if (StringUtils.isEmpty(status)) return false;
/* 226 */     ManageSet manageSet = new ManageSet();
/* 227 */     manageSet.setCode(code);
/* 228 */     manageSet.setStatus(status);
/* 229 */     manageSet.setMValue(value);
/* 230 */     return this.manageSetDAO.updateManageSetByCode(manageSet);
/*     */   }
/*     */ 
/*     */   public List getBackupFiles(File file, List backupFiles)
/*     */   {
/* 240 */     BackupData backupData = new BackupData();
/* 241 */     if (file == null) return null;
/* 242 */     if (file.isDirectory()) {
/* 243 */       File[] files = file.listFiles();
/* 244 */       for (int i = 0; i < files.length; i++)
/* 245 */         getBackupFiles(files[i], backupFiles);
/*     */     }
/*     */     else
/*     */     {
/* 249 */       backupData.setBackupDate(DateUtils.stringDateConvertDate(file.getName().substring(5, file.getName().indexOf(".sql")), "yyyyMMddHHmmss"));
/* 250 */       backupData.setBackupName(file.getName());
/* 251 */       backupData.setBackupWay(file.getName().substring(0, 1));
/* 252 */       backupData.setPath(file.getPath());
/* 253 */       backupFiles.add(backupData);
/*     */     }
/* 255 */     return backupFiles;
/*     */   }
/*     */ 
/*     */   public static void main(String[] args)
/*     */   {
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.service.impl.BackupDataServiceImpl
 * JD-Core Version:    0.6.0
 */